package unit5.part8;

public class AnonymousTest {
    public static void main(String[] args) {
        Timer timer = new Timer();
        ConcreteLogic logic = new ConcreteLogic();
        timer.run(logic);// 传入正常实参
        timer.run(new Logic() {// 简化：传入匿名内部类
            @Override
            public String process() {
                return 1 + 2 + "";
            }
        });
        timer.run(() -> 1 + 2 + "");// 简化：传入Lambda表达式
    }
}


interface Logic {
    String process();
}

class Timer {// 计时器

    void run(Logic logic) {
        System.out.println("开始执行");
        long start = System.currentTimeMillis();
        String result = logic.process();
        long time = System.currentTimeMillis() - start;
        System.out.println("结果：" + result + "，耗时：" + time);
    }
}

class ConcreteLogic implements Logic {
    @Override
    public String process() {
        return 1 + 2 + "";
    }
}


